﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ModelLibrary;

namespace WebC
{
    public partial class base_branddevice : clsBaseForm
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadInfo();
            }
        }

        public void loadInfo()
        {
            BaseInfo baseinfo = null;
            string sModelName = "";
            DataTable dt = null;
            try
            {
                baseinfo = new BaseInfo();
                if (!checkModelRightById(536, ref sModelName, (clsBaseLib)baseinfo))
                {
                    errorUrl(string.Format("你没有“{0}”的权限,请与管理员联系！", sModelName));
                    return;
                }
                sModelFullName = sModelName;
                lbBrandName.Text = baseinfo.getBrandNameById(m_Id);
                dt = baseinfo.getBrandDevice(m_Id);
            }
            catch (Exception e)
            {
                errorUrl(Convert.ToString(e));
            }
            finally
            {
                if (baseinfo != null)
                {
                    baseinfo.Dispose();
                }
            }
            tree.ininTree(dt, tvBrandDevice, false);

        }

        int m_Id
        {
            get
            {
                return Convert.ToInt32(Request["id"]);
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string sIds = "0" + tree.getTreeNodes(tvBrandDevice.Nodes);
            BaseInfo baseinfo = null;
            try
            {
                baseinfo = new BaseInfo();
                baseinfo.setBrandDevice(m_Id, sIds);
            }
            catch (Exception ex)
            {
                errorUrl(Convert.ToString(ex));
            }
            finally
            {
                if (baseinfo != null)
                {
                    baseinfo.Dispose();
                }
            }
            ClientScript.RegisterStartupScript(this.GetType(), "savsuc", "<script>alert('保存成功！');</script>");
        }

        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("brandlist.aspx");
        }
    }
}